<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
var rob = function(nums) {
    var max1 = 0
    var max2 = 0
    for( var i = 0 ; i<nums.length ; i=i+2 ){
        max1 = max1 + nums[i]
    }
    for( var i = 1 ; i<nums.length ; i=i+2 ){
        max2 = max2 + nums[i]
    }
    return Math.max( max1 , max2 )
};

var nums = [2,7,9,3,1]
console.log(rob(nums))
    </script>
</body>
</html>